import React,{Component} from 'react';
import PropTypes from 'prop-types';

class TodoItem extends Component{
  constructor(props){
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }
  render() {
    const {content,test} = this.props;
    //接收父组件传入的值
    return (
      <div onClick={this.handleClick}>
        {test}{content}
      </div>
    )
    {/*不通过JFX来写 return React.createElement('div',{},'React.createElement('')')*/}
  }
  handleClick(){
    //调用父组件handleItemDelete用于删除
    //alert(this.props.index);
    const {deleteItem,index} = this.props;
    deleteItem(index);
  }
}
//属性校验
TodoItem.propTypes = {
  test:PropTypes.string.isRequired,
  //content:PropTypes.oneOfType(PropTypes.number,PropTypes.string),
  deleteItem:PropTypes.func,
  index:PropTypes.number
}
//默认值
TodoItem.defaultProps = {
  test:''
}


export default TodoItem;
